<?php
/**
 * 
 * AreaAction.class.php (ajax 获取地址)
 *
 * @package      	jgsat
 * @author          liuxun QQ:147613338 <admin@jgsat.cn>
 * @copyright     	Copyright (c) 2008-2011  (http://www.jgsat.com)
 * @license         http://www.jgsat.com/license.txt
 * @version        	jgsat企业网站管理系统 v2.1 2011-03-01 jgsat.cn $
 */
if(!defined("JGsat")) exit("Access Denied");
class AjaxAction extends BaseAction
{
    public function index()
    {
	 exit;
    }
    public function procat()
    {
        $catmodule = M('Category');
        $brandmodule = M('Brand');
        $id = intval($_REQUEST['id']);
        $level= intval($_REQUEST['level']);
        $provinceid= intval($_REQUEST['provinceid']);
        $cityid= intval($_REQUEST['cityid']);

        $province_str='<option value="0">请选择分类...</option>';
        $city_str='<option value="0">请选择品牌...</option>';
        $str ='';
        
        if($level==0){
            $r = $catmodule->where("parentid=".$id)->select();	 		
            foreach($r as $key=>$pro){
                $selected = ( $pro['id']==$provinceid) ? ' selected="selected" ' : '';
                $str .='<option value="'.$pro['id'].'"'.$selected.'>'.$pro['catname'].'</option>';
            }
            $province_str .=$str;
        }elseif($level==1){
            $r = $brandmodule->where("status=1 and catid=".$id)->select();	 		
            foreach($r as $key=>$pro){
                $selected = ( $pro['id']==$cityid) ? ' selected="selected" ' : '';
                $str .='<option value="'.$pro['id'].'"'.$selected.'>'.$pro['name'].'</option>';
            }
            $city_str .=$str;
        }
        $str='';
        if($provinceid){
            $r = $brandmodule->where("status=1 and catid=".$provinceid)->select();	 		
            foreach($r as $key=>$pro){
                $selected = ( $pro['id']==$cityid) ? ' selected="selected" ' : '';
                $str .='<option value="'.$pro['id'].'"'.$selected.'>'.$pro['name'].'</option>';
            }
            $city_str .=$str;
        }

        $res=array();
        $res['data']= $rs ? 1 : 0 ;
        $res['province'] =$province_str;
        $res['city'] =$city_str;
        echo json_encode($res); exit;
	exit;
    } 
    public function standard(){
        $module = M('Standard');
        $id = intval($_REQUEST['id']);
        $prostandard= $_REQUEST['p_standard'];
        $str ='';
        $idlist="";
        
        $r = $module->where("status=1 and catid=".$id)->order("id")->limit(2)->select();
        foreach($r as $key=>$pro){
            if($key==0){
                $idlist.=$pro["id"];
            }
            else{
                $idlist.=",".$pro["id"];
            }
            $str .="<p><b>".$pro["name"]."</b><input type='hidden' name='sta_".$pro["id"]."_n' id='sta_".$pro["id"]."_n' value='".$pro["name"]."' /><input type='hidden' name='sta_".$pro["id"]."_t' id='sta_".$pro["id"]."_t' value='".$pro["stype"]."' /><input type='hidden' name='stasel_".$pro["id"]."' id='stasel_".$pro["id"]."' value='' /></p>";
            $str .="<ul class='color_tab clearfloat'>";
            $str .=$this->standardhtml($pro["stype"],$pro["id"],$pro["itemname"]);
            $str .="</ul>";
        }
        if($r){
            $str .="<p><input type='button' name='createstandard' id='createstandard' onclick='javascript:createstandard2()' value='生成价格列表' /></p>";
            $str .="<div class='colorsize' id='pricelist'></div>";
        }
        $res=array();
        $res['data']= $rs ? 1 : 0 ;
        $res['count'] =count($r);
        $res['idlist'] =$idlist;
        $res['htmlstr'] =$str;
        echo json_encode($res); exit;
	exit;
    }
    
    public function standardhtml($st,$sid,$str=""){
        $htmlstr="";
        if($st==1){
            if($str){
                $items=explode( "\r\n",$str);
                $i=0;
                foreach ($items as $r) {
                    if(strstr($r,"|")){
                        $color=explode( "|",$r);
                        $htmlstr.="<li><input type='checkbox' name='sta_".$sid."' class='foar_radio' value='".$i."|".$color[0]."' /><i class='color_box' style='background-color:".$color[1]."'></i>".$color[0]."</li>";
                    }
                    else{
                        $htmlstr.="<li><input type='checkbox' name='sta_".$sid."' class='foar_radio' value='".$i."|".$r."' />".$r."</li>";
                    }
                    $i++;
                }
            }
            else{
                $htmlstr.="<input type='text' name='sta_".$sid."' /><br />请手动输入,如果多项请以\";\"(不包括引号并且是英文符号)隔开.";
            }
        }
        else{
            $htmlstr.="<input type='text' name='sta_".$sid."' /><br />请手动输入,如果多项请以\";\"(不包括引号并且是英文符号)隔开.";
        }
        return $htmlstr;
    }
    public function fastLogin(){
        $username=$_REQUEST['un'];
        $password=$_REQUEST['pw'];
        $ucode=$_REQUEST['ucode'];
        $module = M('User');
        $res=array();
        
        if(empty($username) || empty($password)){
            $res['ok']= "no" ;
            $res['msg'] ="帐号或者密码不能为空！";
            echo json_encode($res);
            exit;
        }
        if(md5($ucode) != $_SESSION['verify']){
            $res['ok']= "no" ;
            $res['msg'] ="验证码错误！";
            echo json_encode($res);
            exit;
        }
        
        $authInfo = $module->getByUsername($username);
        //使用用户名、密码和状态的方式进行认证
        if(empty($authInfo)) {
            $res['ok']= "no" ;
            $res['msg'] ="会员不存在！";
            echo json_encode($res);
            exit;
        }
        else {
            if($authInfo['password'] != sysmd5($_REQUEST['pw'])) {
                $res['ok']= "no" ;
                $res['msg'] ="帐号或者密码错误！";
                echo json_encode($res);
                exit;
            }
            if($authInfo['status'] != 1) {
                $res['ok']= "no" ;
                $res['msg'] ="此帐号还没有审核！";
                echo json_encode($res);
                exit;
            }

            $cookietime =  intval($_REQUEST['cookietime']);
            $cookietime = $cookietime ? $cookietime : 0;

            $jgsat_auth_key = sysmd5($this->sysConfig['ADMIN_ACCESS'].$_SERVER['HTTP_USER_AGENT']);
            $jgsat_auth = authcode($authInfo['id']."-".$authInfo['groupid']."-".$authInfo['password'], 'ENCODE', $jgsat_auth_key);

            cookie('auth',$jgsat_auth,$cookietime);
            cookie('username',$authInfo['username'],$cookietime);
            cookie('groupid',$authInfo['groupid'],$cookietime);
            cookie('userid',$authInfo['id'],$cookietime);
            cookie('email',$authInfo['email'],$cookietime);

            //保存登录信息
            $dao = M('User');
            $data = array();
            $data['id']	=	$authInfo['id'];
            $data['last_logintime']	=	time();
            $data['last_ip']	=	 get_client_ip();
            $data['login_count']	=	array('exp','login_count+1');
            $dao->save($data);

            $res['ok']= "yes" ;
            echo json_encode($res);
            exit;
        }
    }
    
    public function insertcomment(){
        $module=M('Comment');
        $res=array();
        if(empty($_REQUEST['content'])){
            $res['data']= 0 ;
            $res['msg'] ="内容不能为空!";
            echo json_encode($res); 
            exit;
        }
        $_REQUEST['content']=safe_replace($_REQUEST['content']);
        if(!$module->create($_REQUEST)) {
            $res['data']= 0 ;
            $res['msg'] ="参数错误!";
            echo json_encode($res); 
            exit;
        }
        //print_r($this->dao);exit;
        $module->userid = $this->_userid;
        $module->username = $this->_username;
        $module->createtime = time();
        $module->updatetime = time();
        $module->status = 1;
        $module->lang = 1;
        $result	=$module->add();
        if(false !== $result) {
            $res['data']= 1 ;
            $res['msg'] ="评论成功!";
            echo json_encode($res); 
            exit;
        }else{
            $res['data']= 0 ;
            $res['msg'] ="评论发布失败,请认真尝试!";
            echo json_encode($res); 
            exit;
        }
    }
}
?>